// export const addHome = async(req,res)=>{
//     const { course ,todayBuy ,monthBuy } = req.body
//     if(!course) return res.fail('课程不能为空')
//     if(!todayBuy) return res.fail('今日购买不能为空')
//     if(!monthBuy) return res.fail('本月购买不能为空')
//     try{
//         const result = {
//             course,
//             todayBuy: Number(todayBuy),
//             monthBuy: Number(monthBuy)
//         }
//         await req.db.courseBuy.create({
//             data: result
//         })
//         res.send({success: true, message: '添加成功'})
//     }catch(e){
//         console.log(e)
//         res.fail({success: false, message: '添加失败'})
//     }
// }

export const getHome = async(req,res)=>{
    let { limit=20 ,page=1 } = req.body
    limit = Number(limit)
    page = Number(page)
   
    try{
        const result = await req.db.courseBuy.findMany({
            skip: (page-1)*limit,
            take: limit
        })
        res.send({success: true, data: result})
    }catch(e){
        console.log(e)
        res.fail({success: false, message: '查询失败'})
    }
}

export const getChartData = async(req,res)=>{
    let { limit=20  } = req.body
    limit = Number(limit)
    try{
        const result = await req.db.chartData.findMany({
            take: limit
        })
        res.send({success: true, data: result})
    }catch(e){
        console.log(e)
        res.fail({success: false, message: '查询失败'})
    }
}

export const getHomeHeader = async(req,res)=>{
    let { limit =20 } = req.body
    limit= Number(limit)
    try{
        const result = await req.db.homeHeader.findMany({
            take:limit
        })
        res.send({success: true,data: result})
    }catch(e){
        res.fail({success: false,message: '查询失败'})
    }
}
// export const getLineData = async(req,res)=>{
//     let { limit =20 } = req.body
//     limit= Number(limit)
//     try{
//         const result = await req.db.homeHeader.findMany({
//             take:limit
//         })
//         res.send({success: true,data: result})
//     }catch(e){
//         res.fail({success: false,message: '查询失败'})
//     }
// }